const express = require("express");
const app = express.Router();
const conf = require("../mod/config");
const request = require("../mod/request");



app.get("/:shop/user/center",function(req, res){
  var shopid = req.params.shop;
  request.send(
    {
      path:"/gw_main/header",
      callback:(data) => {
        res.render("user/index", {
          title : "个人中心", 
          name : "userCenter", 
          conf:conf,
          shopId : shopid
        });
      },error:(err) => {
        res.render("404", {
          conf:conf
        });
      },
      clientReq:req
    });
});

app.get("/:shop/agreement",function(req, res){
  var shopid = req.params.shop;
  res.render("user/reg-agreement", {
    title : "注册协议",
    conf:conf,
    shopId : shopid
  });
});
app.get("/:shop/login",function(req, res){
  var
  title = "手机登录",
  shopid = req.params.shop;
  if(shopid == "188827"){
    title = "登录"
  }
  res.render("user/login", {
    title : title,
    name : "user", 
    conf:conf,
    shopId : shopid
  });
});
app.get("/:shop/register",function(req,res){
  var shopid=req.params.shop;
  res.render("user/register",{
    title:"快速注册",
    name:"user",
    conf:conf,
    shopId:shopid,
    action:'register'
  })
});
app.get("/:shop/resetPwd",function(req,res){
  var shopid=req.params.shop;
  res.render("user/register",{
    title:"重置密码",
    conf:conf,
    shopId:shopid,
    action:'reset'
  })
});
app.get("/:shop/modifyPwd",function(req,res){
  var shopid=req.params.shop;
  res.render("user/register",{
    title:"修改密码",
    conf:conf,
    shopId:shopid,
    action:'modify'
  })
})
app.get("/:shop/user/orderList",function(req, res){
  var shopid = req.params.shop;
  res.render("user/order-list", {
    title : "我的订单", 
    name : "order", 
    conf:conf,
    shopId : shopid
  });
});
app.get("/:shop/user/orderDetail",function(req, res){
  var shopid = req.params.shop;
  res.render("user/order-detail", {
    title : "订单详情", 
    name : "user", 
    conf:conf,
    shopId : shopid
  });
});
app.get("/:shop/user/eticketList",function(req, res){
  var shopid = req.params.shop;
  res.render("user/ticket-list", {
    title : "我的电子票", 
    name : "user", 
    conf:conf,
    shopId : shopid
  });
});
app.get("/:shop/user/eticketDetail",function(req, res){
  var imgUrl = req.query.ticket,shopid = req.params.shop;
  if(imgUrl){
    imgUrl = imgUrl.split(",")
  }
  res.render("user/ticket-detail", {
    title : "电子票信息",
    name : "user",
    conf:conf,
    shopId : shopid
  });
});

module.exports = app;